package com.example.runningman.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.request.RequestOptions;
import com.example.runningman.R;
import com.example.runningman.bean.Steps;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.TimeZone;

import androidx.recyclerview.widget.RecyclerView;

public class Bushu_adapter extends RecyclerView.Adapter<Bushu_adapter.ViewHolder> {
    List<Steps> mData;
    Activity mActivity;

    boolean f =false;
    public Bushu_adapter(List<Steps> data, Activity activity) {
        this.mData = data;

        this.mActivity = activity;

    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v;

        v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycle_bushu, parent, false);



        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Log.e("sdas", mData.get(position).getTime()+":::::"+mData.get(position).getStep()+"");
            if(mData.get(position).getTime()!=0&&mData.get(position).getStep()!=0){
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));

                String s = sdf.format(mData.get(position).getTime());
                String f =mData.get(position).getStep()+"";
//            f=f.substring(0,f.indexOf("."));
                holder.run_content.setText(s+"    "+f);
            }




    }



    @Override
    public int getItemCount() {
        return mData == null ? 0 : mData.size();
    }

    public void refresh(List<Steps> data){
        this.mData = data;
        notifyDataSetChanged();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView run_content;


        public ViewHolder(View itemView) {
            super(itemView);

            run_content = itemView.findViewById(R.id.bushu_content);



        }
    }

}